Preserve request exception context - #581
Open
phily245 wants to merge 4 commits into
Open
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves exception handling in the PHP SDK by preserving the original Guzzle exception as the chained cause for transport/request-level failures, while introducing a dedicated SDK RequestException for those failures.
Changes:
- Add
UKFast\SDK\Exception\RequestExceptionand update client request handling to wrap transport/request failures with the original Guzzle exception asprevious. - Extend SDK exception constructors to support exception chaining (code + previous) without changing the external exception contract for API failures.
- Add a unit test asserting the original Guzzle exception is preserved when a request fails.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ClientTest.php | Adds coverage to ensure request failures preserve the original Guzzle exception as the chained cause. |
| src/Client.php | Wraps request/transport failures in a dedicated SDK RequestException and chains original exceptions. |
| src/Exception/UKFastException.php | Extends the base SDK exception constructor to support chaining. |
| src/Exception/RequestException.php | Introduces a dedicated SDK exception type for transport/request failures. |
| src/Exception/ApiException.php | Updates API exception construction to use the base constructor (supports chaining). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
All it did wascopy the constructor from the parent Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Client.php:137
Client::request()now wraps allGuzzleException/RequestExceptionfailures into SDK exceptions (e.g.Exception\RequestException,Exception\ClientException,Exception\ServerException) and no longer allowsGuzzleExceptionto bubble up. The method PHPDoc still advertises@throws GuzzleException, which is misleading for SDK consumers and contradicts the new exception-contract goal of this PR. Update the docblocks forrequest()(and the convenience methods that delegate to it) to declare the SDK exceptions actually thrown.
throw new Exception\RequestException($e->getMessage(), $e->getCode(), $e);
} catch (GuzzleException $e) {
throw new Exception\RequestException($e->getMessage(), $e->getCode(), $e);
}
These now match what they actually are
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing